import { reqCategoryList, reqGetBannerList, reqFloorlist } from '@/api'

// 仓库存储数据
const state = {
  categoryList: [],
  bannerList: [],
  floorList: []
}
// 修改state的唯一手段
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  FLOORLIST(state,floorList) {
    state.floorList = floorList
  }
}
// 处理action，可以书写自己的业务逻辑，也可以处理异步
const actions = {
  // 这里的commit用于修改 Vuex store 中状态的函数
  async getCategoryList({ commit }) {
    const result = await reqCategoryList()
    if (result.code === 200) {
      // 调用commit函数，将result.data（分类列表数据）提交到 store 中
      commit('CATEGORYLIST',result.data)
    }
  },
  async getBannerList({ commit }) {
    let result = await reqGetBannerList()
    if (result.code === 200) {
      commit('BANNERLIST',result.data)
    }
  },
  async getFloorlist({ commit }) {
    let result = await reqFloorlist()
    if (result.code === 200) {
      commit('FLOORLIST',result.data)
    }
  }
}
// 类似于计算属性
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}